﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SelfManagement.IServices
{
    public interface IBaseService<T> where T : class, new()
    {
        T New();

        T Get(Expression<Func<T, bool>> predicate);

        T Get(string id);

        IQueryable<T> Query(Expression<Func<T, bool>> predicate = null);

        bool Insert(T obj, bool saveChange = true);
        bool Update(T obj, Func<T, object[]> getKeys = null, bool saveChange = true, bool updateTime = true);
        bool Delete(T obj, bool saveChange = true);

        bool InsertBatch(IEnumerable<T> objs);
        bool UpdateBatch(Expression<Func<T, bool>> predicate, Func<T, T> setter);
        bool DeleteBatch(Expression<Func<T, bool>> predicate);

        bool SaveChanges();

        /// <summary>
        /// 获取数据，并缓存全表
        /// </summary>
        /// <param name="refresh">强制刷新缓存</param>
        /// <returns>全表数据</returns>
        List<T> CacheFullTable(bool refresh = false);


    }
}
